home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Documentation / Tech Notes & Articles / Recipes / Scripting / 7-Scripting Update 5⁄23⁄95 < prev    next >
Encoding:
Text File  |  1995-07-11  |  4.4 KB  |  88 lines  |  [TEXT/ttxt]

  1. Scripting Update-5/23/95
  2. by the OpenDoc Design Team
  3. May 23th, 1995
  4.  
  5.  
  6. © 1995  Apple Computer, Inc. All Rights Reserved.
  7. Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
  8. Mac and OpenDoc are trademarks of Apple Computer, Inc.
  9.  
  10. EmbeddedFrameSpec
  11.  
  12. Here’s how you should call this method.
  13.  
  14. ODOObjectSpec*   spec = new ODOObjectSpec;
  15. spec->InitODObjectSpec(ev);
  16.  
  17. container->EmbeddedFrameSpec(..., frame, spec);
  18.  
  19. Remember that this call might fail if a part up the containment chain does not support it. However, you should always try making this call first because your container knows best how to represent you as an embedded frame, and may be asked to resolve this reference to you later. If the call does fail, you should create an object specifier that describes yourself in some other way such as by persistent object ID.
  20.  
  21. Token inquiry proc
  22.  
  23. All instances of this special callback proc are gone. Instead, if a token represents an embedded frame, that token will either be in the format of a standard part token, or will be able to be coerced to one.
  24.  
  25. GetUserToken/SetUserToken
  26.  
  27. The old style of usage was based on copy semantics. When you called GetUserToken, you got a copy of your token from the OpenDoc token. If you wanted to add content to that token and have the change reflected in the OpenDoc token, you needed to call SetUserToken.
  28.  
  29. The new style of usage allows you to manipulate the user token directly. OpenDoc returns a reference to your user token instead of a copy. SetUserToken is gone. You only need use GetUserToken. GetUserToken will return you a reference to an ODDesc which is your token. When you need to add content to your token, you only need to change the contents of the ODDesc. OpenDoc owns the user token and will pass around the reference and will dispose of it when appropriate.
  30. This is similiar to the model in the application world where the OSL passes you a reference to an AEDesc and you fill it in and return. You don’t need to tell the OSL, “Hey, I’ve changed this token now.”.
  31.  
  32. ODDesc
  33.  
  34. There are now four public methods on this class that allow you to set and get the raw data and to set and get the descriptor type. You can use these methods to convert from AEDescs to ODDescs and back. In fact, the utility routines ODDescToAEDesc and AEDescToODDesc have been rewritten to use these public methods of ODDesc.
  35.  
  36. ODOSLToken
  37.  
  38. One public method was implemented for ODOSLToken, DuplicateODOSLToken. When making a copy of an ODOSLToken, you must use this method.
  39.  
  40. ODDescToAEDesc/AEDescToODDesc/AEDescChanged
  41.  
  42. These routines are no longer required in order to use scripting in OpenDoc. However, they are still very useful.
  43.  
  44. The rules for using these routines were very convoluted and hard to understand.
  45.  
  46. The new rules are simple: the AEDesc is always copied. The ODDesc is always a reference to an existing ODDesc.
  47. Thus you should always call AEDisposeDesc on a descriptor that you’ve gotten from an ODDesc or that you have put into an ODDesc (assuming that you’re done with it). If an ODDesc has existing content, it will be deleted when AEDescToODDesc is called. AEDescChanged is gone.
  48.  
  49. Some sample code
  50.  
  51. Manipulating the user token
  52.  
  53. for inspection (example: examing the container token in an object accessor or other callback):
  54.  
  55. ODDesc* userTokenODDesc;
  56. AEDesc userTokenAEDesc;
  57.  
  58. nameResolver->GetUserToken(ev, containerODDesc, &userTokenODDesc);
  59. ODDescToAEDesc(userTokenODDesc, &userTokenAEDesc);
  60. examine userTokenAEDesc
  61. AEDisposeDesc(userTokenAEDesc);
  62.  
  63. for modification (example: adding content to the user token in an object accessor):
  64.  
  65. AEDesc userTokenAEDesc;
  66. set up your token…manipulate only the AEDesc…call AECreateDesc, AEPutParamDesc, whatever…
  67. ODDesc* userTokenODDesc;
  68. nameResolver->GetUserToken(ev, valueODDesc, &userTokenODDesc);
  69. AEDescToODDesc(&userTokenAEDesc, userTokenODDesc);
  70. AEDisposeDesc(userTokenAEDesc);
  71.  
  72. There is a utility routine available called UpdateODDesc that performs the last four lines of the preceeding code sample.
  73.  
  74. Handling the Apple event message and reply in your event handler
  75.  
  76. AEDesc messageAEDesc;
  77. AEDesc replyAEDesc;
  78.  
  79. ODDescToAEDesc(messageODDesc, &messageAEDesc);
  80. ODDescToAEDesc(replyODDesc, &replyAEDesc);
  81. examine the Apple event…
  82. add stuff to the reply if appropriate…
  83. AEDescToODDesc(&replyAEDesc, replyODDesc); // Only necessary if you’ve added stuff to the
  84.                                            //  reply
  85. AEDisposeDesc(&replyAEDesc);
  86. AEDisposeDesc(&messageAEDesc);
  87.  
  88.